var PITCHWISE = PITCHWISE || {};
PITCHWISE.book = PITCHWISE.book || {};

PITCHWISE.book = function (options) {
    'use strict';

    this.slotID = options.slotID;
    this.pitchID = options.pitchID;
    this.venueID = options.venueID;
    this.startTime = options.startTime;
    this.endTime = options.endTime;
    this.day = options.day;
    this.date = options.date;

    //this.authenticated = options.authenticated;
    this.el = {
        'bookForm':$('#book-form')
    };

    console.log('PITCHWISE.book.options', options);
    this.load();
};
PITCHWISE.book.prototype.events = function () {
    var _this = this;

    _this.el.bookForm.on('submit', function (e) {
        $('.alert').slideUp();

        var input_data = $(this).serialize();
        console.log(input_data);
        $.ajax({
            type:"POST",
            url:"http://pitchwise.co.uk/ajax/",
            data:input_data,
            success:function (msg) {
                msg = $.parseJSON(msg);
                console.log('ajax response', msg);

                $('.alert').html('RESPONSE SUCCESS<br>' + msg.info).slideDown();
                if (msg.url != undefined) {
                    window.location.href = msg.url;
                }
            },
            error:function (msg) {
                console.log(msg);
                $('.-alert').html('RESPONSE ERROR<br>' + msg).slideDown();

            }

        });
        return false;
    });

};
PITCHWISE.book.prototype.init = function () {
};

PITCHWISE.book.prototype.load = function () {
    this.events();
    this.init();
};